package com.tczs.web.service;

import com.alibaba.fastjson.JSONObject;
import com.tczs.client.service.ClientService;
import com.tczs.web.util.JWTUtil;

public class LoginService {

    /**
     * 登录
     * @param username
     * @param password
     * @return
     */
    public JSONObject login(String username, String password){
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("commandName","login");
        jsonObject.put("username",username);
        jsonObject.put("password",password);
        String send = ClientService.send(null, jsonObject);
        JSONObject result = JSONObject.parseObject(send);
        if(result.getInteger("code") == 200) {
            result.put("token", JWTUtil.buildJWT(username));
        }
        return result;
    }
}
